package k2_oop.p8_javaUtil;

import java.time.Duration;
import java.time.LocalDate;
import java.time.Period;

public class UseLocalDate {

    public static void testLocalDate(){

        LocalDate currentDate = LocalDate.now();
        System.out.println(currentDate);

        LocalDate specifiedDate = LocalDate.of(2024,8,1);
        System.out.println(specifiedDate);
//
//        //从1970年1月1日开始的第多少天
//        LocalDate firstDate = LocalDate.ofEpochDay(1);
//        System.out.println(firstDate);
//
//        //LocalDate类型可以转成LocalDateTime类型
//        LocalDateTime currentDateTime = currentDate.atTime(10,10,10);
//        System.out.println(currentDateTime);
//
//        System.out.println(currentDate.getYear());
//        System.out.println(currentDate.getMonth());
//        System.out.println(currentDate.getDayOfMonth());
//        System.out.println(currentDate.getDayOfWeek());
//        System.out.println(currentDate.getDayOfYear());
//        System.out.println(currentDateTime.getHour());
//        System.out.println(currentDateTime.getMinute());
//        System.out.println(currentDateTime.getSecond());
//        System.out.println(currentDateTime.getNano());

//        LocalDate otherDate = currentDate
//                .withYear(2000)
//                .withMonth(6);
//
//        System.out.println(otherDate);
//
//
//        System.out.println(currentDate.isBefore(otherDate));
//        System.out.println(currentDate.isAfter(otherDate));
//        System.out.println(currentDate.equals(otherDate));
//        System.out.println(otherDate.isLeapYear());


//        currentDate = currentDate
//                .plusYears(5)
//                .minusMonths(2);
//
//        System.out.println(currentDate);
//
//        String date = currentDate.format(DateTimeFormatter.ofPattern("yyyy/M/d"));
//        System.out.println(date);
//
//        LocalDate date1 = LocalDate.parse("2022/2/2",DateTimeFormatter.ofPattern("yyyy/M/d"));
//        System.out.println(date1);

        Duration duration = Duration.between(currentDate.atTime(10,10,10),specifiedDate.atTime(11,11,11));
        System.out.println(duration.toHours());
        System.out.println(duration.toDays());
        System.out.println(duration.toSeconds());


        Period period = Period.between(currentDate,specifiedDate);
        System.out.println(period.getYears());
        System.out.println(period.getMonths());
        System.out.println(period.getDays());


    }


    public static void main(String[] args) {
        UseLocalDate.testLocalDate();
    }

}
